package com.zengqingfa.juc.n3;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author zengqingfa
 * @className TestCreateThread3
 * @description
 * @create 2021/6/5 20:45
 */
@Slf4j(topic = "c.TestCreateThread3")
public class TestCreateThread3 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        /**
         * 21:19:19 [t1] c.TestCreateThread3 - runing...1
         * 21:19:19 [main] c.TestCreateThread3 - 结果：100
         */
        FutureTask<Integer> futureTask=new FutureTask<Integer>(()->{
            log.debug("runing...1");
            return 100;
        });
        Thread thread = new Thread(futureTask, "t1");
        thread.start();
        //get方法阻塞，直到拿到结果
        log.debug("结果：{}",futureTask.get());
    }
}